package com.xxd.spring.boot.demo.zhuhongbing.exception;

import com.xxd.spring.boot.demo.zhuhongbing.util.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;

@ControllerAdvice
public class MyExceptionHandler {
    @ExceptionHandler(value=MyException.class)
    @RequestBody
    public Result exceptionHandler(MyException e){
        System.out.println("未知异常！原因是："+e.getMessage());
        Result result=new Result();
        result.setCode(e.getCode());
        result.setMessage(e.getMessage());
        return result;
    }
}
